<?php
class programme_premium extends Model
{
    public static function getTableName()
    {
        return 'programme_premium';
    }

    public function getPrimaryKey()
    {
        return array('programme_id');
    }

    public function set($obj)
    {
        $this->programme_id = isset($obj->id) ? $obj->id : ''; 
        $this->title_en = isset($obj->premium_title_en) ? $obj->premium_title_en : '';
        $this->title_zh = isset($obj->premium_title) ? $obj->premium_title : '';
        $this->auto_publish = isset($obj->premium_auto_publish) ? $obj->premium_auto_publish : 0;
        $this->ppv_flag = !empty($obj->premium_items) && in_array('ppv',$obj->premium_items) ? 1 : 0;
        $this->subscription_flag = !empty($obj->premium_items) && in_array('subscription',$obj->premium_items) ? 1  : 0; 
    }

    public function insert($obj = NULL)
    {
		if (!empty($obj)) {
        	return Model::$dbo['w']->insert($obj);
		} else {
        	return Model::$dbo['w']->insert($this);
		}
    }

    public function update($obj)
    {
        return Model::$dbo['w']->save($obj);
    }

    public function delete($id)
    {
        return Model::$dbo['w']->delete('programme_premium','programme_id=?',array($id));
    }
}
?>
